import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'

// vuex 里面数据的持久化存储
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    app,
    settings,
    user
  },
  getters,
  plugins: [createPersistedState({
    reducer(state) {
      // return 的结构需要跟state里面的数据结构保持一致
      return {
        user: {
          loginInfo: state.user.loginInfo,
          tokenTime: state.user.tokenTime
        }
      }
    }
  })]
})

export default store
